﻿using Prism.Ioc;
using Prism.Modularity;
using Prism.Unity;
using SmartParkingClient.BLL;
using SmartParkingClient.DAL;
using SmartParkingClient.IBLL;
using SmartParkingClient.IDAL;
using SmartParkingClient.Views;
using System.Configuration;
using System.Data;
using System.Net.Http;
using System.Windows;
using System.Windows.Threading;

namespace SmartParkingClient
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : PrismApplication
    {
        public App()
        {
            //WebAPI 功能测试
            //客户端 通过http://localhost:5000/WeatherForecast
            //请求数据资源
            //HttpClient httpClient = new HttpClient();
            //httpClient.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW50aXR5L2NsYWltcy9uYW1lIjoiYWRtaW4iLCJleHAiOjE3NDAyNDI1MTMsImlzcyI6IndlYmFwaS5jbiIsImF1ZCI6IldlYkFwaSJ9.lfm5z6dfTUdVV_Th9O3uFxBzVJBMlyDAnyP9ar79ZBw");
            //var resp = httpClient.GetAsync("http://localhost:5000/api/login").GetAwaiter().GetResult();
            //string values = resp.Content.ReadAsStringAsync().GetAwaiter().GetResult();    // Json

            // 进一步的需要进行反序列化

            // ADO.NET   请求数据库

            // 判断条件    true      C++
        }

        protected override Window CreateShell()
        {
            return Container.Resolve<MainWindow>();
        }

        protected override void RegisterTypes(IContainerRegistry containerRegistry)
        {
            //ConfigurationManager    包一层
            containerRegistry.Register(typeof(Dispatcher), obj => Application.Current.Dispatcher);

            containerRegistry.Register<IWebDataAccess, WebDataAccess>();
            containerRegistry.Register<ILocalDataAccess, LocalDataAccess>();

            // Dal的注册
            containerRegistry.Register<ILoginDal, LoginDal>();
            containerRegistry.Register<IFileDal, FileDal>();
            containerRegistry.Register<IMenuDal, MenuDal>();

            // BLL的注册
            containerRegistry.Register<ILoginBLL, LoginBLL>();
            containerRegistry.Register<IFileBLL, FileBLL>();
            containerRegistry.Register<IMenuBLL, MenuBLL>();
        }

        protected override void InitializeShell(Window shell)
        {
            if (Container.Resolve<Views.WinLogin>().ShowDialog() == true)
                shell.Show();// 不能使用ShowDialog，会导致后续Module无法加载

            // Application.Current.Shutdown();
            // 这句不需要了
        }

        protected override IModuleCatalog CreateModuleCatalog()
        {
            // 自动更新的时候    自动扫描目录
            return new DirectoryModuleCatalog() { ModulePath = Environment.CurrentDirectory + "\\Modules" };
        }
    }

}
